import {
  receiveOrder,
  testOrder,
  produceOrder,
  returnOrder,
} from "@/api/wisdom-beam/collect-app.js";
export default {
  data() {
    return {
      form: {
        //梁号
        componentParts: "",
        //桥梁名称
        bridgeName: "",
        //幅别
        amClass: "",
        //跨
        span: "",
        //梁类型
        beamTypeDesc: "",
        //下单人员
        createrName: "",
        //下单时间
        createTime: "",
        //钢筋设计量
        gjInfoList: [],
        //计划完成时间
        planCompleteTime: "",
        //退回备注
        returnOrderDesc: "",
        //领取时间
        testTime: "",
        //是否合格
        testResult: 0,
        //生产时间
        produceTime: "",
        //生产用量
        produceUsage: "",
        //生产加工信息
        scJgList: [
          {
            rebarModel: undefined,
            rebarDiameter: undefined,
            rebarType: undefined,
            //数量
            rebarNum: "",
          },
        ],
        //钢筋质检信息
        completeTime: "",
        //图片Id集合
        completeFileIds: [],
        imageList: [],
        //钢筋型号
        rebarModelSource: [],
        //钢筋直径
        rebarDiameterSource: [],
        //钢筋品种
        rebarTypeSource: [],
      },
      rules: {},
      span_1: {
        xs: 24,
        sm: 24,
        md: 24,
        lg: 12,
        xl: 12,
        xxl: 6,
      },
      span_2: {
        xs: 24,
        sm: 24,
        md: 24,
        lg: 12,
        xl: 12,
        xxl: 8,
      },
    };
  },
  mounted() {},
  methods: {
    checkPanelList() {
      let { completeStatus } = this.row;
      switch (completeStatus) {
        //接单
        case 0:
          if (this.type == 1) {
            this.panelList = [
              {
                key: "1",
                header: "基本信息",
              },
              {
                key: "2",
                header: "钢筋设计量",
              },
              {
                key: "3",
                header: "接单信息",
              },
            ];
          } else if (this.type == 2) {
            this.panelList = [
              {
                key: "1",
                header: "基本信息",
              },
              {
                key: "2",
                header: "钢筋设计量",
              },
              {
                key: "4",
                header: "退回信息",
              },
            ];
          } else {
            this.panelList = [
              {
                key: "1",
                header: "基本信息",
              },
              {
                key: "2",
                header: "钢筋设计量",
              },
            ];
          }
          break;
        //已退单
        case 1:
          this.panelList = [
            {
              key: "1",
              header: "基本信息",
            },
            {
              key: "2",
              header: "钢筋设计量",
            },
            {
              key: "4",
              header: "退回信息",
            },
          ];
          break;

        //生产加工信息
        case 2:
          if (this.type == 3) {
            this.panelList = [
              {
                key: "1",
                header: "基本信息",
              },
              {
                key: "2",
                header: "钢筋设计量",
              },
              {
                key: "3",
                header: "接单信息",
              },
              {
                key: "5",
                header: "生产加工信息",
              },
            ];
          } else {
            this.panelList = [
              {
                key: "1",
                header: "基本信息",
              },
              {
                key: "2",
                header: "钢筋设计量",
              },
              {
                key: "3",
                header: "接单信息",
              },
            ];
          }
          break;

        //钢筋质检信息
        case 3:
          if (this.type == 4) {
            this.panelList = [
              {
                key: "1",
                header: "基本信息",
              },
              {
                key: "2",
                header: "钢筋设计量",
              },
              {
                key: "3",
                header: "接单信息",
              },
              {
                key: "5",
                header: "生产加工信息",
              },
              {
                key: "6",
                header: "钢筋质检信息信息",
              },
            ];
          } else {
            this.panelList = [
              {
                key: "1",
                header: "基本信息",
              },
              {
                key: "2",
                header: "钢筋设计量",
              },
              {
                key: "3",
                header: "接单信息",
              },
              {
                key: "5",
                header: "生产加工信息",
              },
            ];
          }
          break;

        //生产中
        case 4:
          if (this.type == 5) {
            this.panelList = [
              {
                key: "1",
                header: "基本信息",
              },
              {
                key: "2",
                header: "钢筋设计量",
              },
              {
                key: "3",
                header: "接单信息",
              },
              {
                key: "5",
                header: "生产加工信息",
              },
              {
                key: "6",
                header: "钢筋质检信息",
              },
            ];
          } else {
            this.panelList = [
              {
                key: "1",
                header: "基本信息",
              },
              {
                key: "2",
                header: "钢筋设计量",
              },
              {
                key: "3",
                header: "接单信息",
              },
              {
                key: "5",
                header: "生产加工信息",
              },
              {
                key: "6",
                header: "钢筋质检信息",
              },
            ];
          }
          break;

        //生产完成
        case 5:
          this.panelList = [
            {
              key: "1",
              header: "基本信息",
            },
            {
              key: "2",
              header: "钢筋设计量",
            },
            {
              key: "3",
              header: "接单信息",
            },
            {
              key: "5",
              header: "生产加工信息",
            },
            {
              key: "6",
              header: "钢筋质检信息",
            },
          ];
          break;
        default:
          break;
      }
    },

    //确定
    onSubmit() {
      this.$refs.form.validate((valid) => {
        if (valid) {
          let { form, row } = this;
          let { id } = row;
          this.buttonLoading = true;
          switch (this.type) {
            //接单
            case 1:
              this.receivingOrders({ id, ...form });
              break;
            //退回
            case 2:
              this.returnOrder({ id, ...form });
              break;
            //生产加工
            case 3:
              this.produceOrder({ id, ...form });
              break;
            //钢筋质检
            case 4:
              this.testOrder({ id, ...form });
              break;

            default:
              break;
          }
        } else {
          return false;
        }
      });
    },

    //接单
    receivingOrders(data) {
      let { id, planCompleteTime } = data;
      receiveOrder({
        id,
        planCompleteTime,
      })
        .then((res) => {
          this.$parent.getTableData();
          this.closeModal();
        })
        .catch((_) => {})
        .finally((_) => {
          this.buttonLoading = false;
        });
    },

    //生产加工
    produceOrder(data) {
      let { id, produceTime, produceUsage, completeTime, scJgList = [] } = data;
      produceOrder({
        id,
        produceTime,
        produceUsage,
        completeTime,
        childList: scJgList,
      })
        .then((res) => {
          this.$parent.getTableData();
          this.closeModal();
        })
        .catch((_) => {})
        .finally((_) => {
          this.buttonLoading = false;
        });
    },
    //钢筋质检
    testOrder(data) {
      let { id, testTime, testResult, completeFileIds = [] } = data;
      testOrder({
        id,
        testTime,
        testResult,
        completeFileIds: completeFileIds.map((v) => v.fileId).toString(),
      })
        .then((res) => {
          this.$parent.getTableData();
          this.closeModal();
        })
        .catch((_) => {})
        .finally((_) => {
          this.buttonLoading = false;
        });
    },

    //退回
    returnOrder(data) {
      let { id, returnOrderDesc } = data;
      returnOrder({ id, returnOrderDesc })
        .then((res) => {
          this.$parent.getTableData();
          this.closeModal();
        })
        .catch((_) => {})
        .finally((_) => {
          this.buttonLoading = false;
        });
    },

    //新增生产加工信息
    addScJgRebar() {
      let baseJson = {
        rebarModel: undefined,
        rebarDiameter: undefined,
        rebarType: undefined,
        //数量
        rebarNum: "",
      };
      this.form.scJgList.push(baseJson);
    },

    //删除生产加工信息
    delScJgRebar(index) {
      this.form.scJgList = this.form.scJgList.filter((_, i) => i != index);
    },
  },
};
